home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / gradius3.c < prev    next >
C/C++ Source or Header  |  2000-04-09  |  5KB  |  222 lines

  1. #include "driver.h"
  2. #include "vidhrdw/konamiic.h"
  3.  
  4.  
  5. #define TOTAL_CHARS 0x1000
  6. #define TOTAL_SPRITES 0x4000
  7.  
  8. unsigned char *gradius3_gfxram;
  9. int gradius3_priority;
  10. static int layer_colorbase[3],sprite_colorbase;
  11. static int dirtygfx;
  12. static unsigned char *dirtychar;
  13.  
  14.  
  15.  
  16. /***************************************************************************
  17.  
  18.   Callbacks for the K052109
  19.  
  20. ***************************************************************************/
  21.  
  22. static void gradius3_tile_callback(int layer,int bank,int *code,int *color)
  23. {
  24.     /* (color & 0x02) is flip y handled internally by the 052109 */
  25.     *code |= ((*color & 0x01) << 8) | ((*color & 0x1c) << 7);
  26.     *color = layer_colorbase[layer] + ((*color & 0xe0) >> 5);
  27. }
  28.  
  29.  
  30.  
  31. /***************************************************************************
  32.  
  33.   Callbacks for the K051960
  34.  
  35. ***************************************************************************/
  36.  
  37. static void gradius3_sprite_callback(int *code,int *color,int *priority_mask)
  38. {
  39.     #define L0 0xaa
  40.     #define L1 0xcc
  41.     #define L2 0xf0
  42.     static int primask[2][4] =
  43.     {
  44.         { L0|L2, L0, L0|L2, L0|L1|L2 },
  45.         { L1|L2, L2, 0,     L0|L1|L2 }
  46.     };
  47.     int pri = ((*color & 0x60) >> 5);
  48.     if (gradius3_priority == 0) *priority_mask = primask[0][pri];
  49.     else *priority_mask = primask[1][pri];
  50.  
  51.     *code |= (*color & 0x01) << 13;
  52.     *color = sprite_colorbase + ((*color & 0x1e) >> 1);
  53. }
  54.  
  55.  
  56.  
  57. /***************************************************************************
  58.  
  59.   Start the video hardware emulation.
  60.  
  61. ***************************************************************************/
  62.  
  63. int gradius3_vh_start(void)
  64. {
  65.     int i;
  66.     static struct GfxLayout spritelayout =
  67.     {
  68.         8,8,
  69.         TOTAL_SPRITES,
  70.         4,
  71.         { 0, 1, 2, 3 },
  72.         { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4,
  73.                 32*8+2*4, 32*8+3*4, 32*8+0*4, 32*8+1*4, 32*8+6*4, 32*8+7*4, 32*8+4*4, 32*8+5*4 },
  74.         { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
  75.                 64*8+0*32, 64*8+1*32, 64*8+2*32, 64*8+3*32, 64*8+4*32, 64*8+5*32, 64*8+6*32, 64*8+7*32 },
  76.         128*8
  77.     };
  78.  
  79.  
  80.     layer_colorbase[0] = 0;
  81.     layer_colorbase[1] = 32;
  82.     layer_colorbase[2] = 48;
  83.     sprite_colorbase = 16;
  84.     if (K052109_vh_start(REGION_GFX1,NORMAL_PLANE_ORDER,gradius3_tile_callback))
  85.         return 1;
  86.     if (K051960_vh_start(REGION_GFX2,REVERSE_PLANE_ORDER,gradius3_sprite_callback))
  87.     {
  88.         K052109_vh_stop();
  89.         return 1;
  90.     }
  91.  
  92.     /* re-decode the sprites because the ROMs are connected to the custom IC differently
  93.        from how they are connected to the CPU. */
  94.     for (i = 0;i < TOTAL_SPRITES;i++)
  95.         decodechar(Machine->gfx[1],i,memory_region(REGION_GFX2),&spritelayout);
  96.  
  97.     if (!(dirtychar = malloc(TOTAL_CHARS)))
  98.     {
  99.         K052109_vh_stop();
  100.         K051960_vh_stop();
  101.         return 1;
  102.     }
  103.  
  104.     memset(dirtychar,1,TOTAL_CHARS);
  105.  
  106.     return 0;
  107. }
  108.  
  109. void gradius3_vh_stop(void)
  110. {
  111.     K052109_vh_stop();
  112.     K051960_vh_stop();
  113.     free(dirtychar);
  114.     dirtychar = 0;
  115. }
  116.  
  117.  
  118.  
  119. /***************************************************************************
  120.  
  121.   Memory handlers
  122.  
  123. ***************************************************************************/
  124.  
  125. READ_HANDLER( gradius3_gfxrom_r )
  126. {
  127.     unsigned char *gfxdata = memory_region(REGION_GFX2);
  128.  
  129.     return (gfxdata[offset+1] << 8) | gfxdata[offset];
  130. }
  131.  
  132. READ_HANDLER( gradius3_gfxram_r )
  133. {
  134.     return READ_WORD(&gradius3_gfxram[offset]);
  135. }
  136.  
  137. WRITE_HANDLER( gradius3_gfxram_w )
  138. {
  139.     int oldword = READ_WORD(&gradius3_gfxram[offset]);
  140.     int newword = COMBINE_WORD(oldword,data);
  141.  
  142.     if (oldword != newword)
  143.     {
  144.         dirtygfx = 1;
  145.         dirtychar[offset / 32] = 1;
  146.         WRITE_WORD(&gradius3_gfxram[offset],newword);
  147.     }
  148. }
  149.  
  150.  
  151.  
  152. /***************************************************************************
  153.  
  154.   Display refresh
  155.  
  156. ***************************************************************************/
  157.  
  158. void gradius3_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  159. {
  160.     static struct GfxLayout charlayout =
  161.     {
  162.         8,8,
  163.         TOTAL_CHARS,
  164.         4,
  165.         { 0, 1, 2, 3 },
  166. #ifdef LSB_FIRST
  167.         { 2*4, 3*4, 0*4, 1*4, 6*4, 7*4, 4*4, 5*4 },
  168. #else
  169.         { 0*4, 1*4, 2*4, 3*4, 4*4, 5*4, 6*4, 7*4 },
  170. #endif
  171.         { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32 },
  172.         32*8
  173.     };
  174.  
  175.     /* TODO: this kludge enforces the char banks. For some reason, they don't work otherwise. */
  176.     K052109_w(0x1d80,0x10);
  177.     K052109_w(0x1f00,0x32);
  178.  
  179.     if (dirtygfx)
  180.     {
  181.         int i;
  182.  
  183.         dirtygfx = 0;
  184.  
  185.         for (i = 0;i < TOTAL_CHARS;i++)
  186.         {
  187.             if (dirtychar[i])
  188.             {
  189.                 dirtychar[i] = 0;
  190.                 decodechar(Machine->gfx[0],i,gradius3_gfxram,&charlayout);
  191.             }
  192.         }
  193.  
  194.         tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
  195.     }
  196.  
  197.     K052109_tilemap_update();
  198.  
  199.     palette_init_used_colors();
  200.     K051960_mark_sprites_colors();
  201.     if (palette_recalc())
  202.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  203.  
  204.     tilemap_render(ALL_TILEMAPS);
  205.  
  206.     fillbitmap(priority_bitmap,0,NULL);
  207.     if (gradius3_priority == 0)
  208.     {
  209.         K052109_tilemap_draw(bitmap,1,TILEMAP_IGNORE_TRANSPARENCY|(2<<16));
  210.         K052109_tilemap_draw(bitmap,2,4<<16);
  211.         K052109_tilemap_draw(bitmap,0,1<<16);
  212.     }
  213.     else
  214.     {
  215.         K052109_tilemap_draw(bitmap,0,TILEMAP_IGNORE_TRANSPARENCY|(1<<16));
  216.         K052109_tilemap_draw(bitmap,1,2<<16);
  217.         K052109_tilemap_draw(bitmap,2,4<<16);
  218.     }
  219.  
  220.     K051960_sprites_draw(bitmap,-1,-1);
  221. }
  222.